package com.liyan.giteewarehouse

import android.content.res.AssetManager
import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import android.media.MediaMetadataRetriever
import android.media.MediaPlayer
import android.net.Uri
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.TextView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.request.RequestOptions
import com.liyan.myapplication.Sunbaobao
import com.liyan.sdk.TaskManager
import java.io.File

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

//        findViewById<TextView>(R.id.tv).setText(Sunbaobao.HelloWorld)

        // 加载资源文件 assets 下的图片 image_test.png
        // 加载资源文件 assets 下的图片 image_test.png
        val path = "file:///android_asset/guide_video1.mp4"
//        Glide.with(this)
//            .load(path)
//            .into(findViewById(R.id.image))


        val openFd = assets.openFd("guide_video1.mp4")

        val fileStreamPath = getFileStreamPath("guide_video1.mp4")


//        MediaPlayer().data

        val list = assets.list(path)

        val file = File(fileStreamPath.path)
        Glide
            .with(this)
            .setDefaultRequestOptions(
                RequestOptions()
                    .frame(0)
                    .centerCrop()
            )
            .load(Uri.fromFile(file))
            .into(findViewById(R.id.image));


    }

    fun getVideoThumb(path: String?): Bitmap? {
        val media = MediaMetadataRetriever()
        media.setDataSource(path)
        return media.frameAtTime
    }
}